package com.example.carconsumer.controller.lwj;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.carinterface.pojo.BusinessOrder;
import com.example.carinterface.pojo.Driver;
import com.example.carinterface.pojo.DriverComment;
import com.example.carinterface.service.lwj.RevisePwdService;
import com.example.carinterface.utils.ResultJson;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jdk.internal.org.objectweb.asm.tree.analysis.Value;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: zdk
 * Date: 2020/09/29 22:01
 * Description:
 * Version: V1.0
 */
@RestController
@RequestMapping(value = "/driver",method = RequestMethod.POST)
@CrossOrigin
public class RevisePwdController {

    @Reference(check = false)
    private RevisePwdService revisePwdService;

    @PostMapping(value = "/driverrevis")
    @ApiOperation(value = "更改密码", responseReference = "根据电话号码更改密码", httpMethod = "post", response = ResultJson.class)
    public ResultJson revisepwd(Driver driver) {
        System.out.println(driver.getTel() + "========" + driver.getPassword());
        int reult = revisePwdService.revisePwd(driver);
        SimpleHash md5 = new SimpleHash("md5", driver.getPassword(), driver.getTel(), 32);
        System.out.println(md5);
        driver.setPassword(md5.toString());
        if (reult > 0) {
            return new ResultJson().setSuccess("更改成功");
        } else {
            return new ResultJson().setFail("更改失败");
        }
    }

    @PostMapping( "/check")
        @ApiOperation(value = "确认可以修改", responseReference = "根据原密码和手机号确认该密码可以更改", httpMethod = "post", response = ResultJson.class)
//    @RequestMapping(value = "/check", method = RequestMethod.POST)
//    public ResultJson CheckPwd( String tel ,String password)
    public ResultJson CheckPwd(@ApiParam("tel:tel,password:password") @RequestBody Map<String,Object> map) {
        String tel = map.get("tel").toString();
        String password = map.get("password").toString();
        System.out.println("=====check=====");
        System.out.println(tel+"===="+password);

        int reult =revisePwdService.querytm(tel,password);
        if (reult >0) {
            return new ResultJson().setSuccess("允许更改");
        } else {
            return new ResultJson().setFail("不能更改");
        }
    }
    @PostMapping( value = "/comment")
    @ApiOperation(value = "查看我的评价", responseReference = "提供身份证查看我的评价", httpMethod = "post", response = ResultJson.class)
    public ResultJson queryComment(@ApiParam("id:id") @RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        System.out.println(id+"========");
        System.out.println("====comment====");
        List<DriverComment> reult =revisePwdService.queryComment(id);
        if (reult.size()>0) {
            return new ResultJson().setSuccess("查看成功",reult);
        } else {
            return new ResultJson().setFail("查看失败");
        }
    }
    @PostMapping("/sal")
    @ApiOperation(value = "查看我的工资", responseReference = "通过司机id查询所有该司机的所有工资", httpMethod = "post", response = ResultJson.class)
    public ResultJson querySal(@ApiParam("driver_id:driver_id") @RequestBody Map<String,Integer> map){
        Integer driver_id = map.get("driver_id");
        System.out.println("sssaaalll=="+driver_id);
        List<BusinessOrder> reult = revisePwdService.querySal(driver_id);
        if (reult.size()>0) {
            return new ResultJson().setSuccess("查看成功",reult);
        } else {
            return new ResultJson().setFail("查看失败");
        }
    }
    @PostMapping("/order")
    @ApiOperation(value = "查看所有订单", responseReference = "通过司机id查询所有该司机的订单", httpMethod = "post", response = ResultJson.class)
    public ResultJson queryOrder(@ApiParam("driver_id:driver_id") @RequestBody Map<String,Integer> map){
        Integer driver_id = map.get("driver_id");
        System.out.println("order=="+driver_id);
        List<Map> reult = revisePwdService.queryOrder(driver_id);
        if (reult.size()>0) {
            return new ResultJson().setSuccess("查看成功",reult);
        } else {
            return new ResultJson().setFail("查看失败");
        }
    }
  @PostMapping("/data")
    @ApiOperation(value = "查看订单详情", responseReference = "通过id（订单号）查询订单详情", httpMethod = "get", response = ResultJson.class)
    public ResultJson queryData( @ApiParam("id:id") @RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        System.out.println("mmmmm"+id);
        Map maps =revisePwdService.queryData(id);

        return new ResultJson().setSuccess("数据",maps);

    }
    @PostMapping("/receving")
    @ApiOperation(value = "接车成功", responseReference = "通过订单号更改订单状态", httpMethod = "post", response = ResultJson.class)
    public  ResultJson receivingOder(@RequestBody Map map){
       Integer businessOrder_id=(Integer) map.get("businessOrder_id");
        Boolean bo = revisePwdService.receivingOder(businessOrder_id);
        System.out.println(businessOrder_id+"contrr");
        if (bo=true){
            return new ResultJson().setSuccess("接车成功");
        }else {
            return new ResultJson().setFail("失败");
        }
    }
    @PostMapping("/recevinga")
    @ApiOperation(value = "完成订单", responseReference = "完成订单更改订单状态", httpMethod = "post", response = ResultJson.class)

    public  ResultJson receivingOdera(@RequestBody Map map){
        Integer businessOrder_id=(Integer) map.get("businessOrder_id");
        Boolean bo = revisePwdService.receivingOdera(businessOrder_id);
        System.out.println(businessOrder_id+"contrr");
        if (bo=true){
            return new ResultJson().setSuccess("司机已到达");
        }else {
            return new ResultJson().setFail("失败");
        }
    } @PostMapping("/recevingb")
    @ApiOperation(value = "去往修车点订单", responseReference = "去往修车点订单更改订单状态", httpMethod = "post", response = ResultJson.class)

    public  ResultJson receivingOderb(@RequestBody Map map){
        Integer businessOrder_id=(Integer) map.get("businessOrder_id");
        Boolean bo = revisePwdService.receivingOderb(businessOrder_id);
        System.out.println(businessOrder_id+"contrr");
        if (bo=true){
            return new ResultJson().setSuccess("去往修车点成功");
        }else {
            return new ResultJson().setFail("失败");
        }
    } @PostMapping("/recevingc")
    @ApiOperation(value = "到达修理厂订单", responseReference = "到达修理厂订单更改订单状态", httpMethod = "post", response = ResultJson.class)

    public  ResultJson receivingOderc(@RequestBody Map map){
        Integer businessOrder_id=(Integer) map.get("businessOrder_id");
        Boolean bo = revisePwdService.receivingOderc(businessOrder_id);
        System.out.println(businessOrder_id+"contrr");
        if (bo=true){
            return new ResultJson().setSuccess("接车成功");
        }else {
            return new ResultJson().setFail("失败");
        }
    } @PostMapping("/recevingd")
    @ApiOperation(value = "去往检车厂", responseReference = "去往检车厂更改订单状态", httpMethod = "post", response = ResultJson.class)

    public  ResultJson receivingOderd(@RequestBody Map map){
        Integer businessOrder_id=(Integer) map.get("businessOrder_id");
        Boolean bo = revisePwdService.receivingOderd(businessOrder_id);
        System.out.println(businessOrder_id+"contrr");
        if (bo=true){
            return new ResultJson().setSuccess("接车成功");
        }else {
            return new ResultJson().setFail("失败");
        }
    } @PostMapping("/recevinge")
    @ApiOperation(value = "到达检测场", responseReference = "到达检测场更改订单状态", httpMethod = "post", response = ResultJson.class)

    public  ResultJson receivingOdere(@RequestBody Map map){
        Integer businessOrder_id=(Integer) map.get("businessOrder_id");
        Boolean bo = revisePwdService.receivingOdere(businessOrder_id);
        System.out.println(businessOrder_id+"contrr");
        if (bo=true){
            return new ResultJson().setSuccess("接车成功");
        }else {
            return new ResultJson().setFail("失败");
        }
    } @PostMapping("/recevingf")
    @ApiOperation(value = "维修中订单 ", responseReference = "维修中订单更改订单状态", httpMethod = "post", response = ResultJson.class)

    public  ResultJson receivingOderf(@RequestBody Map map){
        Integer businessOrder_id=(Integer) map.get("businessOrder_id");
        Boolean bo = revisePwdService.receivingOderf(businessOrder_id);
        System.out.println(businessOrder_id+"contrr");
        if (bo=true){
            return new ResultJson().setSuccess("接车成功");
        }else {
            return new ResultJson().setFail("失败");
        }
    }
    @PostMapping("/recevingg")
    @ApiOperation(value = "维修完成", responseReference = "订单 更改订单状态", httpMethod = "post", response = ResultJson.class)

    public  ResultJson receivingOderg(@RequestBody Map map) {
        Integer businessOrder_id=(Integer) map.get("businessOrder_id");
        Boolean bo = revisePwdService.receivingOderg(businessOrder_id);
        System.out.println(businessOrder_id + "contrr");
        if (bo = true) {
            return new ResultJson().setSuccess("接车成功");
        } else {
            return new ResultJson().setFail("失败");
        }
    }
    @PostMapping("/map")
    @ApiOperation(value = "地图参数", responseReference = "查看地图坐标", httpMethod = "post", response = ResultJson.class)
    public ResultJson mapLode(@ApiParam("id:id") @RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        System.out.println("map=="+id);
        List<Map> reult = revisePwdService.queryOrder(id);
        if (reult.size()>0) {
            return new ResultJson().setSuccess("查看成功",reult);
        } else {
            return new ResultJson().setFail("查看失败");
        }
    }
    @PostMapping("/suc")
    @ApiOperation(value = "完成订单", responseReference = "已经完成了的订单", httpMethod = "post", response = ResultJson.class)
    public ResultJson sucOder(@ApiParam("id:id") @RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        System.out.println("sucs=="+id);
        List<Map> reult = revisePwdService.queryOrder(id);
        if (reult.size()>0) {
            return new ResultJson().setSuccess("查看成功",reult);
        } else {
            return new ResultJson().setFail("查看失败");
        }
    }

    @PostMapping("/jiedan")
    @ApiOperation(value = "接单", responseReference = "接单", httpMethod = "post", response = ResultJson.class)
    public ResultJson jiedan(@ApiParam("id:id") @RequestBody Map<String,Integer> map){
     return   revisePwdService.jiedan(map);
    }


}

